package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsSearchHistory;
import com.qf.service.SearchHistoryService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.0
 * @auther Administrator
 * @date 2023/2/24 15:29
 */
@RequestMapping("/admin/history")
@RestController
@CrossOrigin
public class SearchHistoryController {
    @Autowired
    private SearchHistoryService searchHistoryService;

    /**
     * http://localhost:8083/admin/history/list?page=1&limit=20&sort=add_time&order=desc
     * GET
     */
    @RequiresPermissions (value = {"admin:history:list"})
    @RequiresPermissionsDesc(menu = {"用户管理","搜索历史"}, button = "查询")
    @GetMapping("/list")
    public Object list(
            Integer userId,
            String keyword,
            String sort,
            String order,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "20") Integer limit
    ){
        IPage<DtsSearchHistory> iPage = searchHistoryService.findListByQuery(userId,keyword,sort,order,page,limit);
        Map data = new HashMap<>();
        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return ResponseUtil.ok(data);
    }
}
